<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link th:href="@{/layui/css/layui.css}" rel="stylesheet"/>
    <link th:href="@{/css/tool.css}" rel="stylesheet"/>

</head>
<body>
<div class="layui-container">
    <table id="table1" lay-filter="test"></table>
<!--    <input type="hidden" th:value="${session.user.id}" id="id">-->
</div>
</body>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="sh">审核</a>
    <a class="layui-btn layui-btn-xs" lay-event="details">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="zbDetail">招标项目</a>
    <!--    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
</script>

<script type="text/html" id="shStatus">
    {{#  if(d.tbInfo.qualFlag == 0){ }}
    <div class="sh0">
        待审核
    </div>
    {{#  } else if(d.tbInfo.qualFlag == 1){ }}
    <div class="sh1">
        审核通过
    </div>
    {{#  } else { }}
    <div class="sh2">
        审核不通过
    </div>
    {{#  } }}

    <div class="shIcon">
        待审核
    </div>
</script>
<script src="/layui/layui.js" charset="utf-8"></script>
<script>
    layui.use(['table', 'util', 'layer'], function () {
        var table = layui.table,
            $ = layui.$,
            util = layui.util,
            layer = layui.layer;

        //第一个实例
        table.render({
            elem: '#table1'
            , height: 312
            , url: '/admin/getSh'//数据接口
            , page: true //开启分页
            , cols: [
                [ //表头
                    {field: 'd.tbInfo.projectId', title: '投标编号', fixed: 'left',templet:"<div>{{d.tbInfo.projectId}}</div>"}
                    ,
                    {
                        field: 'd.tbInfo.createTime', title: '提交日期', templet: function (d) {
                            return util.toDateString(d.tbInfo.createTime, 'yyyy-MM-dd HH:mm:ss');
                        }
                    }
                    , {field: 'd.zbInfo.title', title: '招标项目名称',templet: "<div>{{d.zbInfo.title}}</div>"}
                    , {field: 'd.tbInfo.qualFlag', title: '审核状态', width: 120, templet: '#shStatus'}
                    , {fixed: 'right', title: '操作', width: 200, toolbar: '#barDemo'}
                ]
            ]
        });

        //监听工具条
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'details') {

                $.ajax({
                    type: "GET",
                    url: "/shPreview/" + data.tbInfo.shFileId,
                    success: function (res) {
                        layer.open({
                            type: 2
                            , title: '资格文件预览'
                            , content: 'http://luckyli.xyz:8012/onlinePreview?url=' + res.url
                            , area: ['500px', '300px']
                            , maxmin: true
                        });
                    }
                });
            } else if(obj.event === 'zbDetail'){
                location.href='/showZb/'+data.zbInfo.id;
            } else if (obj.event === 'sh') {
                // layer.open({
                //     type: 2,
                //     title: '资格审核',
                //     area: ['500px', '300px'],
                //     content: '/admin/shDetail/' +data.zbInfo.id+'/'+data.tbInfo.id,
                //     skin: 'layui-layer-molv'
                // });
                layer.confirm('招标项目审核', {
                    btn: ['通过', '不通过'] //按钮
                }, function () {
                    $.ajax({
                        type: 'post',
                        url: '/admin/tbZiGeSh',
                        data: {
                            status: 1,
                            zbId: data.zbInfo.id,
                            tbId: data.tbInfo.id
                        },
                        success: function (res) {
                            if (res.code == 200) {
                                location.reload();
                            }
                        }
                    })
                }, function () {
                    $.ajax({
                        type: 'post',
                        url: '/admin/tbZiGeSh',
                        data: {
                            status: 2,
                            zbId: data.zbInfo.id,
                            tbId: data.tbInfo.id
                        },
                        success: function (res) {
                            if (res.code == 200) {
                                location.reload()
                            }
                        }
                    })
                });
            }
        });

    })
    ;
</script>
</html>